function handleApplyJob(jobId) {
    console.log('Applying for job:', jobId);
    
    // 获取csrf token
    const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;

    // 显示确认对话框
    Swal.fire({
        title: '确认申请',
        text: '确定要申请这个职位吗？',
        icon: 'question',
        showCancelButton: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonColor: '#1e3c72',
        cancelButtonColor: '#d33'
    }).then((result) => {
        if (result.isConfirmed) {
            // 发送申请请求
            fetch(`/job_apply/${jobId}/apply/`, {
                method: 'POST',
                headers: {
                    'X-CSRFToken': csrfToken,
                    'Content-Type': 'application/json',
                    'X-Requested-With': 'XMLHttpRequest'
                },
            })
            .then(response => response.json())
            .then(data => {
                if (data.status === 'success') {
                    Swal.fire({
                        title: '申请成功！',
                        text: data.message,
                        icon: 'success',
                        confirmButtonColor: '#1e3c72'
                    });
                } else {
                    throw new Error(data.message);
                }
            })
            .catch(error => {
                Swal.fire({
                    title: '申请失败',
                    text: error.message || '提交申请时发生错误',
                    icon: 'error',
                    confirmButtonColor: '#1e3c72'
                });
            });
        }
    });
}